﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace ListViewDemo
{
    /// <summary>
    /// FDataGridDemo.xaml 的交互逻辑
    /// </summary>
    public partial class FDataGridDemo : Window
    {
        private ObservableCollection<item明细表行> tDataGridItem { get; } = new ObservableCollection<item明细表行>();
        public FDataGridDemo()
        {
            InitializeComponent();
            InitializeDatas();
            datagrid明细表.ItemsSource= tDataGridItem;
        }

        private void InitializeDatas()
        {
            for (int i = 0; i < 20; i++)
            {
                tDataGridItem.Add(new item明细表行 { IsChecked = false, Index = 0, _产品编码 = $"00{i}", 
                    _代号 = $"Dx7pk41x{i}", 
                    _名称及规格 = $"连接轴{i}",
                    _材料 = $"#{i}35",
                    _备注 = $"{i}发黑处理",
                    _数量 = 3,
                    _单件 = $"{i}1.5",
                    _总计 = $"{i}4.5",
                    _图纸类型 = "有图件" 
                });
            }
        }
    }

    public class item明细表行 : INotifyPropertyChanged
    {
        // 实现INotifyPropertyChanged接口
        public event PropertyChangedEventHandler PropertyChanged;
        protected void OnPropertyChanged([CallerMemberName] string propertyName = null)
        {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
        }

        public bool IsChecked { get; set; } = false;
        public int Index { get; set; } = 0;
        public string _产品编码 { get; set; } = "";
        public string _代号 { get; set; } = "";
        public string _名称及规格 { get; set; } = "";
        public string _材料 { get; set; } = "";
        public string _备注 { get; set; } = "";
        public string _图纸类型 { get; set; } = "";
        public int _数量 { get; set; } = 0;
        public string _单件 { get; set; } = "";
        public string _总计 { get; set; } = "";

        public void setPropertyChanged()
        {
            OnPropertyChanged();
        }
    }
}
